export function getValueByPath(obj: object, path: string, defaultValue: any) {
    let result = obj
    const paths = path.replace(/\[(\d+)\]/g, '.$1').split('.')
    paths.forEach(value => {
        result = Object(result)[value]
        if (result === undefined)
            return defaultValue
    })
    return result
}

export function setValueByPath(obj: object, path: string, value: any) {
    let result = Object(obj)
    const paths = path.replace(/\[(\d+)\]/g, '.$1').split('.')
    paths.forEach((v, i) => {
        if (i === paths.length - 1) {
            result[v] = value
            return obj;
        } else {
            if (result[v] === undefined) {
                result[v] = {}
            }
            result = result[v]
        }
    })
    return obj;
}